home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 03 control flow and error handling / errorhandlingdemo / classes.vb < prev    next >
Encoding:
Text File  |  2002-03-16  |  961 b   |  35 lines

  1. ' an example of custom exception class
  2.  
  3. ' By convention, the name of all classes that inherit 
  4. ' from System.Exception must end with "Exception"
  5.  
  6. Class UnableToLoadIniFileException
  7.     Inherits System.ApplicationException
  8.  
  9.     Overrides ReadOnly Property Message() As String
  10.         Get
  11.             Return "Unable to load initialization file"
  12.         End Get
  13.     End Property
  14. End Class
  15.  
  16. ' an modified version that also supports inner exceptions
  17.  
  18. Class InitializationFailedException
  19.     Inherits System.ApplicationException
  20.  
  21.     ' we need this to support parameterless constructor
  22.     Sub New()
  23.         '
  24.     End Sub
  25.  
  26.     ' Custom constructor method
  27.     Sub New(ByVal inner As System.Exception)
  28.         MyBase.New("Unable to load initialization file", inner)
  29.     End Sub
  30.  
  31.     ' note that we don't need to override the Message property in this new version
  32.     ' because it is initialized in the base class constructor
  33. End Class
  34.  
  35.